{template 'common/header'}
{template 'common'}
<ul class="nav nav-tabs">
    <li {if $operation=='display'} class="active" {/if}>
    <a href="{php echo $this->createWebUrl('insurance',array('op' =>'display'))}">保险类型列表</a>
    </li>
    <li {if empty($insurance['id']) && $operation == 'post'} class="active" {/if}>
    <a href="{php echo $this->createWebUrl('insurance',array('op' =>'post'))}">添加保险类型</a>
    </li>
    {if !empty($insurance['id']) && $operation == 'post'}
    <li class="active">
        <a href="{php echo $this->createWebUrl('insurance',array('op' =>'post','id'=>$insurance['id']))}">编辑保险类型</a>
    </li>
    {/if}
</ul>

<!--列表-->
{if $operation == 'display'}
<div class="main panel panel-default">
    <div class="panel-body table-responsive">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:30px;">ID</th>
                <th>背景图</th>
                <th>类型名称</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $list $insurance}
            <tr>
                <td>{$insurance['id']}</td>
                <td>
                    <img src="{php echo tomedia($insurance['thumb'])}" width="40">
                </td>
                <td>{$insurance['name']}</td>
                <td style="text-align:left;">
                    <a href="{php echo $this->createWebUrl('insurance', array('op' => 'post', 'id' => $insurance['id']))}"
                       class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改">
                        <i class="fa fa-edit"></i>
                    </a>
                    <a href="{php echo $this->createWebUrl('insurance', array('op' => 'delete', 'id' => $insurance['id']))}"
                       class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="删除">
                        <i class="fa fa-times"></i>
                    </a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
    `
</div>
<script>
    require(['bootstrap'], function ($) {
        $('.btn').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
    });
</script>

<!--增加修改-->
{elseif $operation == 'post'}
<div class="main">
    <form id="form1" action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{$insurance['id']}"/>
        <div class="panel panel-default">
            <div class="panel-heading">
                保险类型设置
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="name">
                        <span style="color:red">*</span>
                        保险名称
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" id='name' name="name" class="form-control" value="{$insurance['name']}"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        保险背景图
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        {php echo tpl_form_field_image('thumb', $insurance['thumb'])}
                        <span class="help-block">图片280*144px</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                权益保障
            </div>
            <div class="panel-body">
                {loop $insurance['security_desc']['security'] $index $security}
                <div class="form-group" id="security_title_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        权益标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="security[security][{$index}][security_title]" class="form-control"
                               value="{$security['security_title']}"/>
                    </div>
                </div>
                <div class="form-group" id="security_price_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        权益金额
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="number" name="security[security][{$index}][security_price]" class="form-control"
                               value="{$security['security_price']}"/>
                    </div>
                </div>
                <div class="form-group" id="security_desc_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        权益描述
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:100px;" class="form-control"
                                  name="security[security][{$index}][security_desc]"
                                  cols="100">{$security['security_desc']}</textarea>
                    </div>
                </div>
                <div class="form-group col-sm-12" id="security_button_{$index}">
                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delSecurity('{$index}');">
                        删除权益
                    </button>
                </div>
                {/loop}
                <div class="form-group col-sm-12" id="addSecurity">
                    <button class="btn btn-info col-lg-1 pull-right" type="button" onclick="addSecurity();">
                        添加
                    </button>
                </div>
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                投保须知
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        <span style="color:red">*</span>
                        标题
                    </label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="notice[title]" class="form-control"
                               value="{$insurance['notice_desc']['title']}"/>
                    </div>
                </div>
                {loop $insurance['notice_desc']['notice'] $index $notice}
                <div class="form-group" id="notice_desc_{$index}">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
                        段落
                    </label>
                    <div class="col-sm-8 col-xs-12">
                        <textarea style="height:100px;" class="form-control"
                                  name="notice[notice][{$index}][notice_desc]"
                                  cols="100">{$notice['notice_desc']}</textarea>
                    </div>
                </div>
                <div class="form-group col-sm-12" id="notice_button_{$index}">
                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delNotice('{$index}');">
                        删除段落
                    </button>
                </div>
                {/loop}
                <div class="form-group col-sm-12" id="addNotice">
                    <button class="btn btn-info col-lg-1 pull-right" type="button" onclick="addNotice();">
                        添加
                    </button>
                </div>
            </div>
        </div>

        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"/>
            <input type="hidden" name="token" value="{$_W['token']}"/>
        </div>
    </form>
</div>

<script language='javascript'>
    var security_num = '{$security_num}';
    var notice_num = '{$notice_num}';
    $(function () {
        $("#form1").submit(function () {
            if ($(":text[name='name']").val() == '') {
                Tip.focus("name", "请填写保险类型名称!");
                return false;
            }
            return true;
        });
    });

    function addSecurity() {
        var html = '<div class="form-group" id="security_title_' + security_num + '">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        权益标题\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-9 col-xs-12">\n' +
            '                        <input type="text" name="security[security][' + security_num + '][security_title]" class="form-control"/>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group" id="security_price_' + security_num + '">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        权益金额\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-9 col-xs-12">\n' +
            '                        <input type="number" name="security[security][' + security_num + '][security_price]" class="form-control"/>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group" id="security_desc_' + security_num + '">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        权益描述\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-8 col-xs-12">\n' +
            '                        <textarea style="height:100px;" class="form-control" name="security[security][' + security_num + '][security_desc]"\n' +
            '                                  cols="100"></textarea>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group col-sm-12" id="security_button_' + security_num + '">\n' +
            '                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delSecurity(' + security_num + ');">\n' +
            '                        删除权益\n' +
            '                    </button>\n' +
            '                </div>' +
            '</div>';
        $('#addSecurity').before(html);
        security_num++;
    }

    function delSecurity(index) {
        $('#security_title_' + index).remove();
        $('#security_price_' + index).remove();
        $('#security_desc_' + index).remove();
        $('#security_button_' + index).remove();
    }

    function addNotice() {
        var html = '<div class="form-group" id="notice_desc_' + notice_num + '">\n' +
            '                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">\n' +
            '                        段落\n' +
            '                    </label>\n' +
            '                    <div class="col-sm-8 col-xs-12">\n' +
            '                        <textarea style="height:100px;" class="form-control" name="notice[notice][' + notice_num + '][notice_desc]"\n' +
            '                                  cols="100"></textarea>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="form-group col-sm-12" id="notice_button_' + notice_num + '">\n' +
            '                    <button class="btn btn-danger col-sm-offset-2" type="button" onclick="delNotice(' + notice_num + ');">\n' +
            '                        删除权益\n' +
            '                    </button>\n' +
            '                </div>' +
            '       </div>';
        $('#addNotice').before(html);
        notice_num++;
    }

    function delNotice(index) {
        $('#notice_desc_' + index).remove();
    }
</script>
{/if}
{template 'common/footer'}